import { Component } from '@angular/core';
import { NavController, ViewController, AlertController, NavParams } from 'ionic-angular';
import { DataService } from '../../services/data';

/**
 * Generated class for the MyCommentPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@Component({
  selector: 'page-my-comment',
  templateUrl: 'my-comment.html',
  providers: [DataService]
})
export class MyCommentPage {

  star:number;
  content:string;
  game_id:number;

  constructor(public navCtrl: NavController, public dataService:DataService, public viewCtrl : ViewController, public navParams: NavParams, public alertCtrl: AlertController) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad MyCommentPage');
  }

  public closeModal(){
    this.viewCtrl.dismiss();
  }

  public send(){
    console.log(1111)
    this.dataService.sendComment(this.navParams.get('game_id'), this.star, this.content).subscribe((data) => {
      if(data.code == 0){
        this.showMessage('发送成功')
      }else{
        this.showMessage('发送失败')
      }
    })
  }

  showMessage(msg){
    let alert = this.alertCtrl.create({
        title: '提示',
        subTitle: msg,
        buttons: [
          {
            text: 'OK',
            handler: () => {
              this.navCtrl.pop();
            }
          }
        ]
      });
      alert.present();
  }

  dismiss() {
    this.viewCtrl.dismiss();
  }

  public rate(i){
    console.log(i)
    this.star = i;
  }

}
